package sz.szsmk.citizencard.mvp.presenter;

import android.widget.Toast;

import com.google.gson.Gson;

import javax.inject.Inject;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.QueryBusLineNearbyReq;
import sz.szsmk.citizencard.model.network.bean.response.QueryBusLineNearbyRes;
import sz.szsmk.citizencard.mvp.contract.INearbyLineContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.ui.activity.IMainActivity;
import sz.szsmk.citizencard.util.Constant;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/29 14:24
 * description:
 */
public class NearbyLinePresenter extends IBasePresenter
        implements INearbyLineContact.INearbyLinePresenter<INearbyLineContact.INearbyLineView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public NearbyLinePresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void queryBusLineNearby(String latitude, String longitude) {
        QueryBusLineNearbyReq nearbyReq = new QueryBusLineNearbyReq();
        //TODO: 获取经纬度
        String json = new Gson().toJson(nearbyReq);
        L.e(Constant.TAG, "公交首页附近线路------requestBody" + json);
        mNetworkDateSource.queryBusLineNearby(nearbyReq, new SubscribeResult<QueryBusLineNearbyRes>() {
            @Override
            protected void onOk(QueryBusLineNearbyRes response) {
                String json = new Gson().toJson(response);
                L.e(Constant.TAG, "公交首页附近线路------" + json);
                ((INearbyLineContact.INearbyLineView) mView).queryBusLineNearbySucc(response);
//                ((IBusHomeLineContact.IBusHomeLineView) mView).getSearchListSucc(response);

            }

            @Override
            protected void onFailure(QueryBusLineNearbyRes response) {
                super.onFailure(response);
                ((INearbyLineContact.INearbyLineView) mView).queryBusLineNearbyFail(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }
}
